
// mixins文件
export default {
  data () {
    return {
      geocoder: null,
      resultText: ''
    }
  },
  created () {
    this.setMap()
  },
  methods: {
    setMap () {
      const newDiv = document.createElement('myMapDiv')
      newDiv.id = 'myMapDiv'
      const init = new Promise((resolve, reject) => {
        if (window.T) {
          console.log('地图初始化成功')
          resolve(window.T)
        }
      })
      init.then(T => {
        // 创建对象
        this.geocoder = new T.Geocoder()
      })
    },
    async searchAddress (address) {
      await this.geocoder.getPoint(address, this.searchResult)
    },
    searchResult (result) {
      this.resultText = `${result.location.lon},${result.location.lat}`
    }
  }
}
